package cn.chengpengper.im.platform.common.interceptor;

import cn.chengpengper.im.platform.common.exception.ImException;
import cn.chengpengper.im.platform.common.interceptor.base.BaseInterceptor;
import cn.chengpengper.im.platform.common.model.enums.HttpCode;
import cn.chengpengper.im.platform.common.risk.rule.service.RuleChainService;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/*@formatter:off*/

/**
 * ____________________
 * < 神兽护体，永无bug! >
 * --------------------
 *
 * @author huchengpeng
 * @version v1.0.0
 * @date 2024/11/23 18:46
 * @description 大后端平台拦截器
 */

/*@formatter:on*/

@Component
public class ImInterceptor extends BaseInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        List<RuleChainService> ruleChainServiceList = this.getRuleChainServiceList();

        for (RuleChainService ruleChainService : ruleChainServiceList) {
            HttpCode httpCode = ruleChainService.execute(request, handler);
            if (!HttpCode.SUCCESS.getCode().equals(httpCode.getCode())) {
                throw new ImException(httpCode);
            }
        }
        return true;
    }
}
